package com.kai.steering.data.service.service.impl;

import com.kai.steering.common.web.service.impl.BaseServiceImpl;
import com.kai.steering.data.service.entity.domainObject.PermissionDO;
import com.kai.steering.data.service.entity.po.Permission;
import com.kai.steering.data.service.mapper.PermissionMapper;
import com.kai.steering.data.service.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Slf4j
@Service
public class PermissionServiceImpl extends BaseServiceImpl<PermissionMapper, Permission>  implements PermissionService {
    @Autowired
    PermissionMapper permissionMapper;

    @Override
    public PermissionDO getPermissionById(String id) {
        Permission permissionById = permissionMapper.getPermissionById(id);
        PermissionDO permissionDO = new PermissionDO(permissionById);
        return permissionDO;
    }

    @Override
    public List<PermissionDO> getPermissonByRole(String roleId) {
        List<Permission> permissionByRole = permissionMapper.getPermissionByRole(roleId);
        List<PermissionDO> collect = permissionByRole.stream().map(permission -> {
            return new PermissionDO(permission);
        }).collect(Collectors.toList());
        return collect;
    }
}
